Skip to content

common: saturate marginal_feerate() instead of overflowing - #9365

Open
morehouse wants to merge 1 commit into
ElementsProject:masterfrom
morehouse:fix_marginal_feerate_overflow
Open

common: saturate marginal_feerate() instead of overflowing#9365
morehouse wants to merge 1 commit into
ElementsProject:masterfrom
morehouse:fix_marginal_feerate_overflow

Conversation

@morehouse

Copy link
Copy Markdown
Contributor

marginal_feerate() computed current_feerate * 1.1 as a double and converted the result back to u32. Since current_feerate is chosen by the peer via open_channel or update_fee, they could choose an absurdly high value that overflows u32 after the computation. UBSan reports:

common/fee_states.c:179:10: runtime error: 4.72446e+09 is outside the range of representable values of type 'unsigned int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior common/fee_states.c:179:10

Do the arithmetic with u64 and saturate at UINT32_MAX to avoid the undefined behavior.

Found by fuzzing with smite.

marginal_feerate() computed current_feerate * 1.1 as a double and
converted the result back to u32.  Since current_feerate is chosen by
the peer in open_channel or update_fee, they could choose an absurdly
high value that overflows u32 after the computation.  UBSan reports:

    common/fee_states.c:179:10: runtime error: 4.72446e+09 is outside the range of representable values of type 'unsigned int'
    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior common/fee_states.c:179:10

Do the arithmetic with u64 and saturate at UINT32_MAX to avoid the
undefined behavior.

Found by fuzzing with smite.

Changelog-Fixed: JSON-RPC: `listpeerchannels` no longer derives `receivable_msat` from an overflowed fee estimate when the peer sets an absurd `feerate_per_kw`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant